package cn.aloxc.tianya.reader;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class Activity_test_spinner extends Activity{
	private final String[] mCountries = {"中国","德国","法国","英国","美国","泰国","蒙古","越南","老挝"};
	private ArrayList<String> allCountries = null;
	private OnItemSelectedListener listener = null,listener2 = null;
	private Spinner spinner = null,spinner2 = null;
	@SuppressWarnings("unchecked")
	public void onCreate(Bundle savedInstanceState){     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_spinner);
        spinner = (Spinner) findViewById(R.id.test_spinner_spinner);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this, R.array.countries, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        
        
        spinner2 = (Spinner)findViewById(R.id.test_spinner_spinner2);
		allCountries = new ArrayList<String>();
		for (int i = 0; i < mCountries.length; i++) {
			allCountries.add(mCountries[i]);
		}
		adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,allCountries);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner2.setAdapter(adapter);       

		listener = new OnItemSelectedListener(){
			public void onItemSelected(AdapterView<?> a, View v,int pos, long arg3) {
				Toast.makeText(Activity_test_spinner.this, ((Spinner)a).getSelectedItem().toString(), Toast.LENGTH_LONG).show();
			}
			public void onNothingSelected(AdapterView<?> arg0) {
				
			}
		};
		listener2 = new OnItemSelectedListener(){
			public void onItemSelected(AdapterView<?> a, View v,int pos, long arg3) {
				Toast.makeText(Activity_test_spinner.this, a.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
			}
			public void onNothingSelected(AdapterView<?> arg0) {
				
			}
		};
		spinner.setOnItemSelectedListener(listener);
		spinner2.setOnItemSelectedListener(listener2);
	}
}
